package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.pubdef.dto.config.ConfigBusinessSwitchUpdateDTO;
import com.qumitech.visualnovel.pubdef.dto.config.ConfigParamUpdateDTO;
import com.qumitech.visualnovel.pubdef.dto.config.ConfigTypeDTO;
import com.qumitech.visualnovel.service.config.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/config")
public class ConfigController {
    @Autowired
    private ConfigService configService;

    @GetMapping(value = "/param")
    public BaseRsp listParam(){
        return configService.listParamDTO();
    }

    @PutMapping("/param/update")
    public BaseRsp updateParam(@RequestBody ConfigParamUpdateDTO updateDTO){
        return configService.updateParam(updateDTO.getKey(), updateDTO);
    }

    @GetMapping(value = "/switch")
    public BaseRsp listSwitch(){
        return configService.listBusinessSwitchDTO();
    }

    @PutMapping(value = "/switch/{business_type}")
    public BaseRsp updateBusinessSwitch(@PathVariable("business_type") Integer businessType,
                                        @RequestBody ConfigBusinessSwitchUpdateDTO updateDTO){
        return configService.updateBusinessSwitch(businessType, updateDTO);
    }

    @GetMapping(value = "/reload")
    public BaseRsp listConfigType() {
        return configService.listConfigType();
    }

    @PostMapping(value = "/reload")
    public BaseRsp reloadConfig(@RequestBody(required = false) ConfigTypeDTO configTypeDTO) {
        configTypeDTO = configTypeDTO == null ? new ConfigTypeDTO() : configTypeDTO;
        return configService.reloadConfig(configTypeDTO);
    }


    @GetMapping("/publicpool")
    public BaseRsp getPublicPool(){
        return configService.getPublicPool();

    }

    @PutMapping("/publicpool/{public_pool}")
    public BaseRsp replacePublicPool(@PathVariable(name = "public_pool") double publicPool){
        return configService.replacePublicPool(publicPool);
    }

    @GetMapping("/supreme_egg/publicpool")
    public BaseRsp getSuprePublicPool(){
        return configService.getSupremeEggPublicPool();
    }

    @PutMapping("/supreme_egg/publicpool/{public_pool}")
    public BaseRsp replaceSupremeEggPublicPool(@PathVariable(name = "public_pool") double publicPool){
        return configService.replaceSupremeEggPublicPool(publicPool);
    }

}
